const API_BASE_URL = '/api';  // 改为/api

// 获取仪表板数据
async function fetchDashboardData() {
    try {
        // 获取教师总数
        const employeesResponse = await fetch(`${API_BASE_URL}/employees`);
        const employees = await employeesResponse.json();
        document.getElementById('totalEmployees').textContent = employees.length;

        // 获取学院数量
        const departments = new Set(employees.map(emp => emp.department));
        document.getElementById('departmentCount').textContent = departments.size;

        // 获取考勤记录计算考勤率
        const attendanceResponse = await fetch(`${API_BASE_URL}/attendance`);
        const attendance = await attendanceResponse.json();
        
        const today = new Date().toISOString().split('T')[0];
        const todayRecords = attendance.filter(record => record.date === today);
        const normalCount = todayRecords.filter(record => record.status === '正常').length;
        const attendanceRate = todayRecords.length > 0 
            ? ((normalCount / todayRecords.length) * 100).toFixed(1)
            : '0.0';
        
        document.getElementById('attendanceRate').textContent = attendanceRate + '%';
    } catch (error) {
        console.error('Error:', error);
    }
}

// 初始化
document.addEventListener('DOMContentLoaded', fetchDashboardData); 